package com.example.springboot.service.impl;

import com.example.springboot.entity.CustomOption;
import com.example.springboot.entity.CustomRequest;
import com.example.springboot.mapper.CustomOptionMapper;
import com.example.springboot.mapper.CustomRequestMapper;
import com.example.springboot.service.CustomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomServiceImpl implements CustomService {

    @Autowired
    private CustomOptionMapper customOptionMapper;
    
    @Autowired
    private CustomRequestMapper customRequestMapper;
    
    @Override
    public Map<String, Object> getCustomizeOptions() {
        Map<String, Object> result = new HashMap<>();
        
        // 获取出行天数选项
        List<CustomOption> durations = customOptionMapper.selectByType("duration");
        result.put("durations", durations);
        
        // 获取预算范围选项
        List<CustomOption> budgets = customOptionMapper.selectByType("budget");
        result.put("budgets", budgets);
        
        // 获取主题选项
        List<CustomOption> themes = customOptionMapper.selectByType("theme");
        result.put("themes", themes);
        
        return result;
    }
    
    @Override
    public boolean submitCustomRequest(CustomRequest request) {
        // 设置初始状态和创建时间
        request.setStatus(0); // 待处理
        request.setCreateTime(new Date());
        request.setUpdateTime(new Date());
        
        // 保存到数据库
        int result = customRequestMapper.insert(request);
        return result > 0;
    }
}